package com.example.gkcircle.activity;

import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.ImageRequest;
import com.bm.library.PhotoView;
import com.example.gkcircle.App;
import com.example.gkcircle.BaseActivity;
import com.example.gkcircle.R;
import com.example.gkcircle.utils.AsynImageLoader;
import com.example.gkcircle.utils.PicUtil;
import com.example.gkcircle.utils.ToastFactory;
import com.example.gkcircle.utils.UniversalImageLoader;

/**
 * Created by Jehu on 16/3/26.
 */
public class PhotoViewAcitivty extends BaseActivity implements View.OnClickListener{

    private PhotoView mPhotoView;

    private Bitmap bitmap;
    @Override
    protected void initView() {
        setContentView(R.layout.photo_view_acitivty);
        mPhotoView=(PhotoView)findViewById(R.id.phone_view_iv);
    }

    @Override
    protected void initListener() {
        mPhotoView.setOnClickListener(this);
    }


    @Override
    protected void setData() {
        // 启用图片缩放功能
        mPhotoView.enable();

        Bundle bundle=getIntent().getExtras();
        String imageUrl=bundle.getString("imageUrl");
        String imagePath=bundle.getString("imagePath");
        String thumbnailUrl=bundle.getString("thumnailUrl");
        if(imagePath!=null){
            bitmap=PicUtil.getBitmap(imagePath);
            mPhotoView.setImageBitmap(bitmap);
            return;
        }
        if(thumbnailUrl!=null){
            UniversalImageLoader.getIntance().displayImage(thumbnailUrl,mPhotoView,UniversalImageLoader.getPhotorOptions(),UniversalImageLoader.getAnimateFirstDisplayListener());
        }
        if(imageUrl==null){
            ToastFactory.getToast(this,"加载失败").show();
            return;
        }
        UniversalImageLoader.getIntance().displayImage(imageUrl,mPhotoView,UniversalImageLoader.getPhotorOptions(),UniversalImageLoader.getAnimateFirstDisplayListener());
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.phone_view_iv:
                finish();
                this.overridePendingTransition(0, R.anim.zoom_out);
                break;

        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(bitmap!=null &&!bitmap.isRecycled()){
            bitmap.recycle();
        }
    }
}
